import { shopAlliance,shopAlliancePay } from "../apis/index.js";

class Alliance {
	
	category = ''
	category_img = ''
	allAD = []
	allSKU
   
   //代理模式
	constructor() {
		// 已经实例化直接返回实例对象
		if (typeof Alliance.instance === 'object') {
			return Alliance.instance;
		}

		// 缓存
		Alliance.instance = this;
		return this;

	}
	
	static async shopAlliancePay(params) {
		return shopAlliancePay({
			...params
		})
	}
	
	async getAllSKU() {
		if(this.allSKU) return
		let allSKU = await shopAlliance()
		this.formartAlliance(allSKU)
	}
	
	formartAlliance(allSKU) {
		this.category = allSKU.category
		this.category_img = allSKU.depositPayment
		let reserve = {
			title: allSKU.depositTitle,
			price: allSKU.depositPrice,
			img: allSKU.shopkeeperAlliancePictures,
			details: allSKU.depositDetails
		}
		let half = {
			title: allSKU.semiannualPaymentTitle,
			price: allSKU.semiannualPaymentPrice,
			img: allSKU.shopkeeperAlliancePictures,
			details: allSKU.semiannualDetails
		}
		let year = {
			title: allSKU.annualPaymentTitle,
			price: allSKU.annualPaymentPrice,
			img: allSKU.shopkeeperAlliancePictures,
			details: allSKU.annualPaymentDetails
		}
		
		this.allSKU = {
			reserve,
			half,
			year
		}
		this.allAD.push({
			name: 'reserve',
			img: allSKU.pictureSemiannualPayment
		})
		this.allAD.push({
			name: 'year',
			img: allSKU.picturesAnnualPayment
		})
	}
}

export {
    Alliance
}